package com.gitee.kenewstar.migration.util;

import java.util.HashMap;
import java.util.Map;
import java.util.Optional;

/**
 * @author kenewstar
 */
public class Util {

    private static final Map<Long, Long> TENANT = new HashMap<>(16);
    private static final Map<String, String> EXECUTOR = new HashMap<>(16);

    private Util() {}

    public static void tenantMap(Long srcTenantId, Long targetTenantId) {
        TENANT.put(srcTenantId, targetTenantId);
    }

    public static void executorMap(String srcExecutorCode, String targetExecutorCode) {
        EXECUTOR.put(srcExecutorCode, targetExecutorCode);
    }

    public static Long getTenant(Long srcTenantId) {
        return Optional.ofNullable(TENANT.get(srcTenantId)).orElse(srcTenantId);
    }
    public static String getTenant(String srcTenantId) {
        Long id = Long.parseLong(srcTenantId);
        return String.valueOf(Optional.ofNullable(TENANT.get(id)).orElse(id));
    }

    public static String getExecutor(String executorCode) {
        return Optional.ofNullable(EXECUTOR.get(executorCode)).orElse(executorCode);
    }


}
